﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinaer.Model.Common;
using Chinaer.Core.Helper;

namespace Chinaer.Bll
{
    public class EmployeeCaoZuo : Repository, IBll.IEmployeeCaoZuo
    {
        private Chinaer.IDao.IEmployee_CaoZuoDAO employeeCaoZuoDAO = new Chinaer.Dao.EmployeeCaoZuoDAO();
        private static EmployeeCaoZuo _instance = null;
        public static EmployeeCaoZuo Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new EmployeeCaoZuo();
                }
                return _instance;
            }
            set
            {
                _instance = value;
            }
        }

        public JsonResult Add(DTO.Employee_CaoZuoDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_Employee_CaoZuo model_EmployeeCaoZuo = new Model.Entities.Model_Employee_CaoZuo();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_EmployeeCaoZuo);
            if (string.IsNullOrEmpty(model_EmployeeCaoZuo.ID) || model_EmployeeCaoZuo.ID.Trim() == "")
            {
                model_EmployeeCaoZuo.ID = Chinaer.Core.Helper.GenerateIDHelper.GenerateID();
            }
            jsonResult.Success = employeeCaoZuoDAO.Add(model_EmployeeCaoZuo);
            return jsonResult;
        }

        public JsonResult Delete(DTO.Employee_CaoZuoDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_Employee_CaoZuo employeeCaoZuo = new Model.Entities.Model_Employee_CaoZuo();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, employeeCaoZuo);
            jsonResult.Success = employeeCaoZuoDAO.Delete(employeeCaoZuo);
            return jsonResult;
        }

        public JsonResult Delete(string id)
        {
            JsonResult jsonResult = new JsonResult();
            jsonResult.Success = employeeCaoZuoDAO.Delete(id);
            return jsonResult;
        }

        public JsonResult Update(DTO.Employee_CaoZuoDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_Employee_CaoZuo employeeCaoZuo = new Model.Entities.Model_Employee_CaoZuo();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, employeeCaoZuo);
            jsonResult.Success = employeeCaoZuoDAO.Update(employeeCaoZuo);
            return jsonResult;
        }

        public DTO.Employee_CaoZuoDTO GetByID(string id)
        {
            Model.Entities.Model_Employee_CaoZuo model_EmployeeCaoZuo = new Model.Entities.Model_Employee_CaoZuo();
            DTO.Employee_CaoZuoDTO employeeCaoZuoDTO = new DTO.Employee_CaoZuoDTO();
            model_EmployeeCaoZuo = employeeCaoZuoDAO.GetByID(id);
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(model_EmployeeCaoZuo, employeeCaoZuoDTO);
            return employeeCaoZuoDTO;
        }
    }
}
